<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-calendar"></i> 表单
                </el-breadcrumb-item>
                <el-breadcrumb-item>新加订单</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container" style="width:250px">
            <div class="form-box" style="width:100%;">
                <el-form ref="form" :model="form" label-width="50px">
                    <el-form-item label="金额">
                        <el-input maxlength='100px' minlength='20px' type="number" v-model="form.order_price"></el-input>
                    </el-form-item>
					<el-form-item label="类型">
					    <el-input v-model="form.order_type"></el-input>
					</el-form-item>
                    <el-form-item label="人员">
                        <el-select v-model="form.memberid" placeholder="请选择">
							  <el-option
							       v-for="item in this.select"
							       :key="item.name"
							       :label="item.name"
							       :value="item.id">
							       <span style="float: left">{{ item.name }}</span>
							       <span style="float: right; color: #8492a6; font-size: 13px">id:{{ item.id }}</span>
							     </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">表单提交</el-button>
                        <el-button>取消</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
import{ addtransaction} from '../../api/index';
import{ getNameAndId} from '../../api/index';
export default {
    data() {
        return {
			form:{
				order_price:'',
				order_type:'',
				memberid:''
			},
			select:''
		}
    },
	created() {
	    this.getData();
	},
    methods: {
		getData() {
		    getNameAndId().then(res => {
		        this.select = res.t;
		    });
		},
        onSubmit() {
			if(this.form.order_price<=0||this.form.order_price==''){
				this.$message.error('金额错误');
			}else{
				addtransaction(this.form).then(res=>{
					this.$message.success('提交成功！');
				}).catch((e)=>{
					this.$message.error()('提交出错！');
				})
			}
        }
    },
};
</script>